package view

import (
    "data"
    "errors"
    "helper/response"
)

type ProductKill struct {
    ca      *data.Cache
}

func NewProductKill() *ProductKill {
    pk := new(ProductKill)
    if pk == nil {
        return nil
    }

    var ca = data.NewCache()
    if ca == nil {
        return nil
    }
    pk.ca = ca
    return pk
}

func (pk *ProductKill) ProductSecKill(productid string) (string, error) {
    if productid == "" {
        err := errors.New("secKill: params error")
        responseStr, _ := response.ProductSecKillInfoResponse(1, nil)
        return responseStr, err
    }
    value, err := pk.ca.GetProductKill(productid)
    if err != nil {
        responseStr, _ := response.ProductSecKillInfoResponse(1, nil)
        return responseStr, err
    } else {
        responseStr, _ := response.ProductSecKillInfoResponse(0, value)
        return responseStr, nil
    }
}
